// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.common.controller;

import java.util.HashMap;
import java.util.Map;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.common.controller.request.QueryHierarchyReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.liuxinlong.common.TreeNode;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.common.service.TreeService;

/**
 * 树结构控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2022年1月26日
 */
@RestController
@RequestMapping("/tree")
public class TreeController {
	@Autowired
	private TreeService treeService;

	/**
	 * 获取层级结构树
	 *
	 * @return 层级结构树
	 */
	@RequestMapping("hierarchy")
	@LogAnnotation(value ="查询层级结构树",business = LogBusinessConstants.TREE_SELECT,operateType = LogOperateConstants.OPERATE_QUERY)
	public BaseResp queryHierarchyTree(@RequestBody QueryHierarchyReq req) {
		TreeNode treeNode = treeService.queryHierarchyTree(req.getActionScope());
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("data", treeNode);
		BaseResp resp = new BaseResp();
		resp.setDataMap(dataMap);
		resp.setRetMessage("查询层级结构树成功");
		return resp;
	}

	/**
	 * 获取菜单树
	 *
	 * @return 菜单树
	 */
	@RequestMapping("menu")
	@LogAnnotation(value ="查询菜单结构树",business = LogBusinessConstants.TREE_SELECT,operateType = LogOperateConstants.OPERATE_QUERY)
	public BaseResp queryMenuTree() {
		TreeNode treeNode = treeService.queryMenuTree();
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("data", treeNode);
		BaseResp resp = new BaseResp();
		resp.setDataMap(dataMap);
		resp.setRetMessage("查询菜单树成功");
		return resp;
	}

	/**
	 * 获取专家组树
	 *
	 * @return 专家组树
	 */
	@RequestMapping("expert-group")
	@LogAnnotation(value ="查询专家组结构树",business = LogBusinessConstants.TREE_SELECT,operateType = LogOperateConstants.OPERATE_QUERY)
	public BaseResp queryExpertGroupTree() {
		TreeNode treeNode = treeService.queryExpertGroupTree();
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("data", treeNode);
		BaseResp resp = new BaseResp();
		resp.setDataMap(dataMap);
		resp.setRetMessage("查询专家组结构树成功");
		return resp;
	}

}
